package com.example.accessdemo.config;

import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * hippo4j线程池配置类
 */
@Configuration
public class ThreadPoolConfig {
    
    @Value("${spring.dynamic.thread-pool.item-id}")
    private String threadPoolId;

    @Bean
    @DynamicThreadPool
    public ThreadPoolExecutor testDynamicExecutor() {
        ThreadPoolExecutor testDynamicExecutor = ThreadPoolBuilder.builder()
                .threadFactory(threadPoolId)
                .threadPoolId(threadPoolId)
                .dynamicPool()
                .build();
        return testDynamicExecutor;
    }

}